]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st-theme: Optimize string_in_list
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 5 Nov 2012 18:36:40 +0000 (13:36 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 5 Nov 2012 20:10:31 +0000 (15:10 -0500)
Rather than using a complicated set of function calls across
library boundaries and our own scanning logic, use strtok(),
which glibc already provides, and is probably much more optimized.

https://bugzilla.gnome.org/show_bug.cgi?id=687465

src/st/st-theme.c

index 77076c09e5635cfcde7ea583a5e4c89b6fb3b249..298cdc8e64f1c294e93a0efa3727d5895e533b12 100644 (file)
@@ -450,26 +450,26 @@ static gboolean
 string_in_list (GString    *stryng,
                 const char *list)
 {
-  const char *cur;
+  char *cur;
+  char *l = g_strdup (list);
+  char *temp;
+  gboolean found = FALSE;
 
-  for (cur = list; *cur;)
+  cur = strtok_r (l, " \t\f\r\n", &temp);
+  while (cur != NULL)
     {
-      while (*cur && cr_utils_is_white_space (*cur))
-        cur++;
-
-      if (strncmp (cur, stryng->str, stryng->len) == 0)
+      if (!strqcmp (cur, stryng->str, stryng->len))
         {
-          cur +=  stryng->len;
-          if ((!*cur) || cr_utils_is_white_space (*cur))
-            return TRUE;
+          found = TRUE;
+          goto out;
         }
 
-      /*  skip to next whitespace character  */
-      while (*cur && !cr_utils_is_white_space (*cur))
-        cur++;
+      cur = strtok_r (NULL, " \t\f\r\n", &temp);
     }
 
-  return FALSE;
+ out:
+  g_free (l);
+  return found;
 }
 
 static gboolean